package wedaex.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import wedaex.content.ContentExtractorSet;
import wedaex.helper.SessionUtils;
import wedaex.helper.XmlHelper;

public class GenerateController implements Controller {
	public static final String TYPE_XML = "xml";
	
	public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String type = request.getParameter("type");
		if(TYPE_XML.equals(type)) {
			ContentExtractorSet set = SessionUtils.getContentExtractorSet(request);
			response.setContentType("application/x-download");
			response.setHeader("Content-Disposition", "attachment; filename=extractor.xml");
			XmlHelper.writeXml(set, response.getOutputStream());
			response.getOutputStream().close();
		}
		return null ;
	}

}
